<?php

namespace app\index\model;

use coser\Db;

class TaskModel
{
    /*
     *[添加主任务]
     */
    public function addMenu($data)
    {
        $res = Db::name('task_menu')->insert($data);
        return $res;
    }
	
	/*
     *[添加任务]
     */
    public function addTask($data)
    {
        $res = Db::name('task_list')->insert($data);
        return $res;
    }

    /*
     *[编辑任务]
     */
    public function editTask($where,$data)
    {
        $res = Db::name('task_list')->where($where)->update($data);
        return $res;
    }

    /*
     *[获取任务详情]
     */
    public function getTaskInfo($where)
    {
        $list = Db::name('task_list')->where($where)->find();

        return $list;
    }

    /*
     *[添加任务类型]
     */
    public function addType($data)
    {
        $res = Db::name('task_type')->insert($data);
        return $res;
    }
	
	
	/*
     *[获取任务列表]
     */
    public function getTasklist($where)
    {
        $list = Db::name('task_list')
                    ->where($where)
					->by('id desc')
                    ->select();

        return $list;
    }

    /*
     *[获取主任务列表]
     */
    public function getMenulist($field,$where,$on)
    {
        $list = Db::name('task_menu')->uas('t1')
                    ->field($field)
                    ->ujoin('task_list ','t2','LEFT')
                    ->uon($on)
                    ->where($where)
                    ->group('t1.id')
					->by('t1.by_time desc')
                    ->select();

        return $list;
    }

    /*
     *[获取主任务详情]
     */
    public function getMenuInfo($where,$on)
    {
        $info = Db::name('task_menu')->uas('t1')
            ->field('t1.*,count(t2.id) as ok_chapter')
            ->ujoin('task_list ','t2','LEFT')
            ->uon($on)
            ->where($where)
            ->group('t1.id')
            ->by('t1.id desc')
            ->find();

        return $info;
    }

    /*
    *[编辑主任务]
    */
    public function editTaskMenu($where,$data)
    {
        $res = Db::name('task_menu')->where($where)->update($data);
        return $res;
    }


    /*
     *[检查类型是否添加]
     */
    public function checkType($where)
    {
        $res = Db::name('task_type')->where($where)->count();
        return $res;
    }


    /*
     *[获取列表]
     */
    public function getList($where)
    {
        $list = Db::name('clock_list')->where($where)->select();
        return $list;
    }

    /*
     * [获取主任务排行榜]
     */
    public function getMeunBoard()
    {
        $list = Db::name('task_menu')
                    ->uas('t1')
                    ->field('t1.title')
                    ->ujoin('task_list','t2','LEFT')
                    ->uon('t1.id = t2.pid and t1.is_del = 1')
                    ->group('t1.type')
                    ->limit(0,10)
                    ->select();

        return $list;
    }
}